Skip to content

fix: keep the status open after a zero-byte ReadFrom - #44

Closed
SashaMIT wants to merge 1 commit into
felixge:masterfrom
SashaMIT:fix/readfrom-zero-status
Closed

SashaMIT wants to merge 1 commit into
felixge:masterfrom
SashaMIT:fix/readfrom-zero-status

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 9, 2026 •

Copy link
Copy Markdown

Summary

CaptureMetrics reported 200 after io.Copy from a reader that failed before any bytes, even when the handler then sent 502. An empty ReadFrom followed by 204 was recorded as 200 as well.

ReadFrom marked the status as written before any byte was copied. A zero-byte ReadFrom does not commit a response, so a later WriteHeader is the status. A copy that writes bytes still records 200 and ignores a later WriteHeader. The client already received 502 or 204 in these cases. Only the captured code was wrong.

Test plan

  • readfrom error then 502 fails on the old hook (got=200 want=502) and passes with this change. The client status is 502.
  • readfrom empty then 204 fails on the old hook (got=200 want=204) and passes with this change. The client status is 204.
  • go test -race -count=1 . passed

Fixes #42

io.Copy from a reader that fails or ends before any bytes does not write a response. CaptureMetrics treated that ReadFrom as a committed 200, so a later 502 or 204 was recorded as 200.

Fixes felixge#42
@jgehrcke

Copy link
Copy Markdown

Bonjour, are we sure that this contribution was guided by a real human being? :) 🐳

@felixge

felixge commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Bonjour, are we sure that this contribution was guided by a real human being? :) 🐳

@jgehrcke IDK about guided, but the PR description was definitely written by an agent. It's not terrible, but nobody would write the test plan like this 😅 . It's been low on my list of things to review as a result.

@jgehrcke

Copy link
Copy Markdown

@felixge looks like we agree :)

I submitted the issue, and would actually love to work on a patch myself in the coming days, does that sound alright? So, we can keep the review effort on this patch here somewhat minimal then maybe :)

@SashaMIT

Copy link
Copy Markdown
Author

That's fair. The description is stiffer than I'd send. Please take the patch. I'll close this so it isn't sitting in the queue.

@SashaMIT SashaMIT closed this Oct 24, 2026
@felixge

felixge commented Oct 24, 2026

Copy link
Copy Markdown
Owner

@jgehrcke would be happy to review a patch from you.

@SashaMIT no worries. I'm not against AI assisted contributions as a matter of policy. I just maintain this project in my free time, so I bias a bit towards contributor/reviewer effort symmetry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CaptureMetrics reports 200 after a zero-byte ReadFrom

3 participants